package org.bizbundles.translate;

import javax.swing.table.AbstractTableModel;

/**
 * Copyright 2007 BizBundle.org
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author Steve Roach
 * @since: Nov 14, 2007
 * 9:28:27 PM
 */
class ResourceTable extends AbstractTableModel
{
    private java.util.List<TableData> tableData;
    private String[] columnNames;

    ResourceTable(java.util.List<TableData> tableData, String[] columnNames)
    {
        this.tableData = tableData;
        this.columnNames = columnNames;
    }

    public int getRowCount()
    {
        return tableData.size();
    }

    public int getColumnCount()
    {
        return columnNames.length;
    }

    public String getColumnName(int col)
    {
        return columnNames[col];
    }

    public Object getValueAt(int row, int col)
    {
        TableData aTableData = tableData.get(row);
        return aTableData.getVale(col);
    }

    /*
    * JTable uses this method to determine the default renderer/
    * editor for each cell.  If we didn't implement this method,
    * then the last column would contain text ("true"/"false"),
    * rather than a check box.
    */
    public Class getColumnClass(int c)
    {
        return getValueAt(0, c).getClass();
    }

    /*
    * Don't need to implement this method unless your table's
    * editable.
    */
    public boolean isCellEditable(int row, int col)
    {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        return true;
    }
}
